package org.opens.mybatisplus.controller;

import org.opens.mybatisplus.entity.LocalDate;
import org.opens.mybatisplus.service.LocalDateService;
import org.opens.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (LocalDate)表控制层
 *
 * @author makejava
 * @since 2020-04-11 10:03:53
 */
@RestController
@RequestMapping("/api")
public class LocalDateController {
    /**
     * 服务对象
     */
    @Resource
    private LocalDateService localDateService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/localDate")
    public LocalDate selectOne(Integer id) {
        return this.localDateService.queryById(id);
    }

    /**
     * 说明:
     *      1. 请求时, 需要将json参数的形式定义为:
     *      ```
     *      {
     *          "name": "s6",
     *          "createDate": "2019-01-04T03:05:05"
     *      }
     *      ```
     *
     */
    @PostMapping(value = "/localDate")
    public R save(
            @RequestBody LocalDate localDate
    ) {
        R success = R.success("保存成功");
        this.localDateService.insert(localDate);
        return success;
    }

}